const Router = require('koa-router');
const addWorks = new Router();
const sqldata = require('./sqldata');
  
addWorks.post('/addworks',async (ctx) => {
    // 添加作品
    let mydata = await new Promise((resolve, reject)=>{
        let val=ctx.request.body;
        const sqlLang = `INSERT INTO works (Uid,Wtitle,Wintro,Wtag,Wzan,Wimage,Wcity,Wtime) VALUES ('${val.Uid}', '${val.Wtitle}', '${val.Wintro}','${val.Wtag}','${val.Wzan}','${val.Wimage}','${val.Wcity}','${val.Wtime}')`;
        return sqldata(sqlLang, (err, data)=>{
            if(err) reject(err);
            resolve(data);	// 返回拿到的数据
        })
    })
    ctx.body=mydata;
})

module.exports = addWorks;